{% load humanize hc_extras  %}

<div class="modal-body">
    <h3>Ping #{{ ping.n }}
        {% if ping.kind == "ign" %}
        <span class="text-muted">(ignored)</span>
        {% elif ping.exitstatus > 0 %}
        <span class="text-danger">(failure, exit status {{ ping.exitstatus }})</span>
        {% elif ping.exitstatus == 0 %}
        <span class="text-success">(exit status 0)</span>
        {% elif ping.kind == "fail" %}
        <span class="text-danger">(received via the <code>/fail</code> endpoint)</span>
        {% elif ping.kind == "start" %}
        <span class="text-success">(received via the <code>/start</code> endpoint)</span>
        {% elif ping.kind == "log" %}
        <span class="text-muted">(received via the <code>/log</code> endpoint)</span>
        {% endif %}
    </h3>

    <div class="row">
        <div class="col-sm-12">
            <p>
                <strong>Time Received</strong>
                <code>{{ ping.created.isoformat }}</code>
                <div class="times" data-dt="{{ ping.created|timestamp }}">
                    {% if check.kind == "simple" or check.tz != "UTC" %}
                    <div>
                        UTC<br>
                        <span data-format="UTC"></span>
                    </div>
                    {% endif %}
                    {% if check.kind == "cron" or check.kind == "oncalendar" %}
                    <div data-format="{{ check.tz }}">
                        {{ check.tz }}<br>
                        <span data-format="{{ check.tz }}"></span>
                    </div>
                    {% endif %}
                    <div>
                        Browser's time zone<br>
                        <span data-format="local"></span>
                    </div>
                </div>

            </p>
        </div>

        <div class="col-sm-6">
            <p>
                <strong>Source</strong>
                {% if ping.scheme == "email" %}
                {{ ping.ua }}
                {% else %}
                    {{ ping.scheme|upper }} {{ ping.method|upper }}
                    {% if ping.remote_addr %}from {{ ping.remote_addr }}{% endif %}
                {% endif %}
            </p>
        </div>

        {% if ping.duration %}
        <div class="col-sm-6">
            <p>
                <strong>Duration</strong>
                <span class="ic-timer"></span> {{ ping.duration|hms }}
            </p>
        </div>
        {% endif %}

        {% if ping.rid %}
        <div class="col-sm-6">
            <p>
                <strong>Run ID</strong>
                <span>{{ ping.rid }}</span>
            </p>
        </div>
        {% endif %}

        {% if ping.scheme != "email" %}
        <div class="col-sm-12">
            <p>
                <strong>User Agent</strong>
                <span class="ua">{{ ping.ua }}</span>
            </p>
        </div>
        {% endif %}

        {% if subject %}
        <div class="col-sm-12">
            <p>
                <strong>Subject</strong>
                <span>{{ subject }}</span>
            </p>
        </div>
        {% endif %}
    </div>

    {% if ping.has_body %}
        <h4>Request Body</h4>

        {% if ping.object_size and not body %}
            <p class="alert alert-info">
                The request body data is not yet available,
                please check back later.
            </p>
        {% else %}
            {% if plain or html %}
            <ul class="nav nav-pills">
                <li>
                    <a href="#email-body-raw" data-toggle="tab">Raw Message</a>
                </li>
                {% if plain %}
                <li{% if active == 'plain' %} class="active"{% endif %}>
                    <a href="#email-body-plain" data-toggle="tab">Text</a>
                </li>
                {% endif %}
                {% if html %}
                <li{% if active == 'html' %} class="active"{% endif %}>
                    <a href="#email-body-html" data-toggle="tab">HTML</a>
                </li>
                {% endif %}
            </ul>
            <div class="tab-content">
                <div id="email-body-raw" class="tab-pane">
                    <pre>{{ body }}</pre>
                </div>

                {% if plain %}
                <div id="email-body-plain" class="tab-pane{% if active == 'plain' %} active{% endif %}">
                    <pre>{{ plain }}</pre>
                </div>
                {% endif %}

                {% if html %}
                <div id="email-body-html" class="tab-pane{% if active == 'html' %} active{% endif %}">
                    <pre>{{ html }}</pre>
                </div>
                {% endif %}
            </div>
            {% else %}
            <pre>{{ body }}</pre>
            {% endif %}
            <p class="download">
                <a href="{% url 'hc-ping-body' check.code ping.n %}">Download Original</a>
            </p>
        {% endif %}
    {% endif %}
</div>
